export const getTimeByMin = (minute) => {
  let d = Math.floor(minute / (60 * 24)) + 1;
  let h = Math.floor(minute / 60) % 24;
  let m = minute % 60;
  h = h < 10 ? `0${h}` : h;
  m = m < 10 ? `0${m}` : m;
  return {
    d,
    h,
    m,
  };
};

export const getBrightnessByTime = (h, m) => {
  // 0-4 最暗, 10-14 最亮
  let hour = Number(h) + Number(m) / 60;

  const maxBrightness = 1;
  const minBrightness = 0.2;

  const sunRise = 4; // 上山
  const sunHoldStart = 10; // 亮度不变开始
  const sunHoldEnd = 14; // 亮度不变结束
  const sunSet = 20; // 下山

  // 没上山
  if ((0 < hour && hour < sunRise) || (sunSet < hour && hour < 24)) {
    return minBrightness;
  }

  // 上升
  if (sunRise <= hour && hour < sunHoldStart) {
    return (
      minBrightness +
      (maxBrightness - minBrightness) *
        ((hour - sunRise) / (sunHoldStart - sunRise))
    );
  }

  // 亮度不变
  if (sunHoldStart <= hour && hour < sunHoldEnd) {
    return maxBrightness;
  }

  // 下降
  if (sunHoldEnd <= hour && hour < sunSet) {
    return (
      maxBrightness -
      (maxBrightness - minBrightness) *
        ((hour - sunHoldEnd) / (sunSet - sunHoldEnd))
    );
  }
};
